import { getAreaObj } from '@/utils/util'
import {configToSearch,toSearchHandle} from '@/views/datacenter/business/utils/index'

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '户籍地区', prop: 'crAreaName' },
		{ label: '证件号码', prop: 'idCard' ,plusXing: '2,2'},
		{ label: '发放对象', prop: 'applicantName' },
		{ label: '联系方式', prop: 'applicantPhone',plusXing: '5,2' },
		{ label: '发放金额', prop: 'grantAmount' },
		{
			label: '申请类别',
			prop: 'applyType',
			propName: 'applyTypeLabel',
			type: 'remoteSelect',
			api: 'getDictItemList',
			code: 'SUBSIDY_APPLICATION_DISBURSEMENT_TYPE',
		},
		{
			label: '银行卡号',
			prop: 'bankAccount',
		},
		{ label: '开户银行', prop: 'bankName' },
		{ label: '发放年月', prop: 'grantDate' },
		{
			label: '是否可信',
			prop: 'isBelievable',
			custome: 'tag',
			dicData: [
				{ label: '否', value: 0,type:'danger' },
				{ label: '是', value: 1,type:'success' },
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}
export const detailConfig: any = {
	label: '尊老金详情',
	prop: 'base1',
	inline: false,
	showBtn: false,
	labelPosition: 'left',
	column: [
		// 申请人信息
		{
			type: 'DividerHtml',
			modelValue: '登记信息',
			span: 24,
		},
		{
			label: '尊老金申请人姓名',
			prop: 'applicantName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '尊老金申请人年龄',
			prop: 'age',
			isNum:true,
			append:'岁',
			type: 'input',
			span: 8,
		},
		{
			label: '尊老金申请人身份证号',
			prop: 'idCard',
			type: 'text',
			maxlength: '18',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '尊老金申请人性别',
			prop: 'gender',
			propName:'genderLabel',
			api:'getDictItemList',
			code:'GENDER',
			type: 'remoteSelect',
			span: 8,
		},
		{
			label: '申请人出生年月',
			prop: 'birthday',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '尊老金申请人联系方式',
			prop: 'applicantPhone',
			type: 'text',
			maxlength: '11',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '申请类别',
			prop: 'applyType',
			propName: 'applyTypeLabel',
			type: 'remoteSelect',
			api: 'getDictItemList',
			code: 'SUBSIDY_APPLICATION_DISBURSEMENT_TYPE',
			span: 8,
		},
		// 需要时
		{
			label: '户籍地区',
			prop: 'cr_areas_name',
			type:"AplidAreaSelect",
			span: 8,
		},
		{
			label: '户籍地址',
			prop: 'crAddress',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '现居地区',
			prop: 'areas_name',
			type:"AplidAreaSelect",
			span: 8,
		},
		{
			label: '现居地址',
			prop: 'address',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '监护人姓名',
			prop: 'guardianName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
		},

		{
			label: '监护人身份证号',
			prop: 'guardianIdCard',
			type: 'text',
			maxlength: '18',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '监护人联系方式',
			prop: 'guardianPhone',
			type: 'text',
			maxlength: '11',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '申请登记日期',
			prop: 'applyDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '申请社区审批时间',
			prop: 'communityApprovalDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '申请社区审批人',
			prop: 'communityApprovalUser',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '申请街道审批时间',
			prop: 'streetApprovalDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '申请街道审批人',
			prop: 'streetApprovalUser',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '申请区审批时间',
			prop: 'areaApprovalDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '申请区审批人',
			prop: 'areaApprovalUser',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '审批结果',
			prop: 'approvalStatus',
			propName:'approvalStatusLabel',
			type:'remoteSelect',
			api:'getDictItemList',
			code:'RESULT',
			span: 8,
		},

		// 申请人信息
		{
			type: 'DividerHtml',
			modelValue: '发放信息',
			span: 24,
		},
		{
			label: '发放类型',
			prop: 'grantType',
			propName:'grantTypeLabel',
			type: 'remoteSelect',
			code:'GRANT_TYPE',
			api:'getDictItemList',
			span: 8,
		},
		{
			label: '尊老金发放年月',
			prop: 'grantDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '尊老金发放金额',
			prop: 'grantAmount',
			type: 'input',
			append:'元',
			span: 8,
		},
		{
			label: '开户银行',
			prop: 'bankName',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '银行卡卡主',
			prop: 'bankCardMaster',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '取款卡类别',
			prop: 'bankCardType',
			propName:'bankCardTypeLabel',
			code:'BANK_CARD_TYPE',
			api:'getDictItemList',
			type: 'remoteSelect',
			span: 8,
		},
		{
			label: '银行卡号',
			prop: 'bankAccount',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		// 补发详情
		{
			type: 'DividerHtml',
			modelValue: '补发详情',
			span: 24,
		},
		{
			label: '尊老金补发开始时间',
			prop: 'supplementStartDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '尊老金补发结束时间',
			prop: 'supplementEndDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '补发总金额',
			prop: 'supplementTotalAmount',
			append:'元',
			type: 'input',
			span: 8,
		},
	],
}
const moreSearchConfig:any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column:[
		...configToSearch(detailConfig.column)
	]
}
const importConfig = {
	tabSteps: [
		{
			label: '下载模板',
			download: '下载模板',
			active: 1,
			rules: [
				{
					label: '下载最新导入模板。共2个：',
					children: [
						{
							label: '《尊老金补贴信息表》',
							link: true,
							url: 'dpVenerableSubsidy_downloadTemplate',
						},
					],
				},
			],
		},
		{
			label: '导入《尊老金补贴信息表》',
			description: '',
			uploadTip: '尊老金补贴信息表',
			active: 2,
			url: 'dpVenerableSubsidy_import',
			code: 3020,
			rules: [
				{
					label: '导入规则说明:',
					children: [
						{
							label: '(1)导入模式为“覆盖导入”，待导入的尊老金补贴信息会覆盖平台已存在的',
						},
					],
				},
			],
		},
	],
}

export const baseConfig: any = {
	pageName: '尊老金',
	dictcodes: ['SUBSIDY_APPLICATION_DISBURSEMENT_TYPE','GENDER','RESULT','GRANT_TYPE','BANK_CARD_TYPE'],
	rowKey: 'id',
	tipLabel: 'applicantName',
	exportMqTopic: '/ning/export',

	api: {
		moreSearch:'view_dpVenerableSubsidy_search',
		index: 'dpVenerableSubsidy_page',
		delete: 'dpVenerableSubsidy_del',
		export: 'dpVenerableSubsidy_export',
		import: 'dpVenerableSubsidy_import',
	},
	paramsObj: {
		code: 3020,
	},
	auth: {
		index: 'view_dpVenerableSubsidy_page',
		delete: 'view_dpVenerableSubsidy_del',
		mulitSet: 'mulitSet',
		export: 'view_dpVenerableSubsidy_export',
		// import: 'view_dpVenerableSubsidy_import',
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '查看详情',
			type: 'primary',
			operate: 'detail',
			auth: '',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '65%',
	},
	moreSearchConfig,
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{
				label: '证件号码',
				prop: 'idCard',
				type: 'input',
				span: 6,
			},
			{
				label: '发放对象',
				prop: 'applicantName',
				type: 'input',
				span: 6,
			},
			{
				label: '联系方式',
				prop: 'applicantPhone',
				type: 'input',
				span: 6,
			},
			{
				label: '户籍地区',
				propName: 'cr_areas_name',
				type: 'AplidAreaSelect',
				span: 6,
			},
			{
				label: '申请类别',
				prop: 'applyType',
				propName: 'applyTypeLabel',
				type: 'remoteSelect',
				api: 'getDictItemList',
				code: 'SUBSIDY_APPLICATION_DISBURSEMENT_TYPE',
				filterKey: 'value',
				multiple: false,
				span: 6,
			},
			{
				label: '申请年月',
				prop: 'applyTimeBetween',
				type: 'daterange',
				format: 'YYYY年MM月DD日',
				valueFormat: 'YYYY-MM-DD',
				span: 12,
			},
		],
	},
	importConfig,
	detailConfig,
	tableConfig,
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			resolve({
				...form,
			})
		})
	},
	beforeOnLoadFormate: async (params) => {
		params = toSearchHandle(moreSearchConfig,{},params)
		if(params.applyTimeBetween){
			params.applyTimeBetween = params.applyTimeBetween.join(',')
		}else{
			params.applyTimeBetween = undefined
		}
		// 将搜索数据改为id和区划名
		
		let crAreasName = getAreaObj(params.cr_areas_name, 'cr')
		return Promise.resolve({
			...params,
			...crAreasName,
			cr_areas_name: undefined,
			undefined:undefined
		})
	},
	onLoadFormate: async (arr) => {
		console.log('列表', arr)
		const tableData = arr.map((item) => {
			let areas_name = getAreaObj(item, '')
			let cr_areas_name = getAreaObj(item, 'cr')
			return {
				...item,
				areas_name,
				cr_areas_name,
			}
		})

		return Promise.resolve(Object.freeze(tableData))
	},
}
